package com.nl.gen.core;

import com.nl.model.consts.ConstPool;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.logging.log4j.util.Strings;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * TemplatePathEnum.
 *
 * @author zenghao
 */
@Getter
@AllArgsConstructor
public enum TemplatePathEnum {

    D_DTO("/dto.ftl", "model/%sDTO.java",
        GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
    D_PARAM("/param.ftl", "model/%sParam.java",
        GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
    D_QUERY("/query.ftl", "model/%sQuery.java",
        GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
    D_SERVICE("/service.ftl", "service/%sService.java",
        GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),

    D_ENTITY("/entity.ftl", "entity/%s.java",
        GenerateUtil.MODULE_DAL, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
    D_MAPPER("/mapper.ftl", "mapper/%sMapper.java",
        GenerateUtil.MODULE_DAL, CategoryEnum.MYBATIS.getValue(), FrameworkEnum.DUBBO.getValue()),
    D_MYBATIS("/mybatis.ftl", "mybatis/%sMapper.xml",
        GenerateUtil.MODULE_DAL, CategoryEnum.MYBATIS.getValue(), FrameworkEnum.DUBBO.getValue()),
//    D_REPOSITORY("/repository.ftl", "repository/%sRepository.java",
//            GenerateUtil.MODULE_SERVICE, CategoryEnum.HIBERNATE.getValue(), FrameworkEnum.DUBBO.getValue()),

    D_CONVERTOR("/convertor.ftl", "convertor/%sConvertor.java",
        GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
    D_IMPL("/impl.ftl", "service/%sServiceImpl.java",
        GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.DUBBO.getValue());

    /************* OPENAPI *************/
//    D_VO("/vo.ftl", "openapi/model/%sVO.java",
//            GenerateUtil.MODULE_OPENAPI, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
//    D_FORM("/form.ftl", "openapi/model/%sForm.java",
//            GenerateUtil.MODULE_OPENAPI, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
//    D_QUERY_FORM("/query_form.ftl", "openapi/model/%sQueryForm.java",
//            GenerateUtil.MODULE_OPENAPI, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
//    D_OPENAPI_MAPPER("/openapi_mapper.ftl", "openapi/mapper/%sMapper.java",
//            GenerateUtil.MODULE_OPENAPI, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),
//    D_CONTROLLER("/controller.ftl", "openapi/controller/%sController.java",
//            GenerateUtil.MODULE_OPENAPI, Strings.EMPTY, FrameworkEnum.DUBBO.getValue()),

    /*********************************************** SPRING_CLOUD *************************************************/

    /************* SERVICE *************/
//    S_ENTITY("/entity.ftl", "entity/%s.java",
//            GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_MAPPER("/convertor.ftl", "mapper/%sMapper.java",
//            GenerateUtil.MODULE_SERVICE, CategoryEnum.MYBATIS.getValue(), FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_MYBATIS("/mybatis.ftl", "mybatis/%sMapper.xml",
//            GenerateUtil.MODULE_SERVICE, CategoryEnum.MYBATIS.getValue(), FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_SERVICE("/service.ftl", "service/%sService.java",
//            GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_IMPL("/impl.ftl", "service/impl/%sServiceImpl.java",
//            GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_FORM("/form.ftl", "web/form/%sQueryForm.java",
//            GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_CONTROLLER("/controller.ftl", "web/controller/%sController.java",
//            GenerateUtil.MODULE_SERVICE, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//
//    /************* API *************/
//    S_FEIGN("/feign.ftl", "feign/I%sClient.java",
//            GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_FALLBACK("/fallback.ftl", "fallback/%sClientFallback.java",
//            GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_DTO("/dto.ftl", "model/%sDTO.java",
//            GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_PARAM("/param.ftl", "model/%sParam.java",
//            GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),
//    S_QUERY_PARAM("/query.ftl", "model/%sQuery.java",
//            GenerateUtil.MODULE_API, Strings.EMPTY, FrameworkEnum.SPRING_CLOUD.getValue()),

    /**
     * 模版文件名.
     */
    private final String templatePath;

    /**
     * 文件输出路径.
     */
    private final String outPath;
    /**
     * 模块名.
     */
    private final String module;

    /**
     * 数据层模版类型 为空则是都支持，否则只支持该模版.
     */
    private final String category;

    /**
     * 框架类型.
     */
    private final String framework;

    /**
     * getTemplates.
     *
     * @param framework framework
     * @return List
     */
    public static List<TemplatePathEnum> getTemplates(final String framework) {
        return Stream.of(TemplatePathEnum.values())
            .filter(t -> t.getFramework().equalsIgnoreCase(framework)).collect(Collectors.toList());
    }

    /**
     * 文件生成后的路径.
     *
     * @param className 类名
     * @return String
     */
    public String genOutPath(final String className) {
        return String.format(getOutPath(), className);
    }

    public String getTemplateName() {
        return name().substring(2);
    }

    /**
     * 获取模版文件的路径.
     *
     * @param category 模版类型
     * @return 框架名 + 模版名 + 模版文件名
     */
    public String genTemplatePath(final String category) {
        return getFramework().concat(ConstPool.SLASH).concat(category).concat(getTemplatePath());
    }
}
